package com.unionfetch.content_home.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.unionfetch.content_home.HomeConstants
import com.unionfetch.content_home.R
import com.unionfetch.content_home.bean.AccountCategory
import com.unionfetch.content_home.bean.TradeAccountModel
import com.unionftech.common.CommonConstants
import com.unionftech.common.common.bean.Platform
import com.unionftech.common.common.contract.CommonContract

class SelectTradeAccountAdapter(list: MutableList<TradeAccountModel>) :
    BaseQuickAdapter<TradeAccountModel, BaseViewHolder>(
        R.layout.layout_select_trade_account_item, list
    ) {
    private var mSelectIndex = -1
    override fun convert(holder: BaseViewHolder, item: TradeAccountModel) {
        //是否选中
        if (mSelectIndex == holder.layoutPosition) {
            holder.setBackgroundResource(R.id.item_container, R.drawable.shape_account_select_bg)
            holder.setGone(R.id.iv_item_select, false)
        } else {
            holder.setBackgroundResource(R.id.item_container, R.drawable.shape_account_unselect_bg)
            holder.setGone(R.id.iv_item_select, true)
        }
        //账号
        holder.setText(R.id.tv_account_no, item.tradeNo)
        //账户类型
        holder.setText(R.id.tv_account_type, item.type.showName)
        if (item.type == AccountCategory.LIVE) {
            holder.setTextColorRes(R.id.tv_account_type, R.color.color_1677FF)
            holder.setBackgroundResource(
                R.id.tv_account_type, R.drawable.shape_live_account_type_bg
            )
        } else {
            holder.setTextColorRes(R.id.tv_account_type, R.color.color_2EBD85)
            holder.setBackgroundResource(
                R.id.tv_account_type, R.drawable.shape_demo_account_type_bg
            )
        }
        //账户状态
        holder.setText(R.id.tv_account_state, item.status.showName)
        //MT4或MT5
        if (item.platform == Platform.MT4.platform) {
            holder.setText(R.id.tv_account_platform, HomeConstants.STR.MT4)
        } else if (item.platform == Platform.MT5.platform) {
            holder.setText(R.id.tv_account_platform, HomeConstants.STR.MT5)
        }
        //余额和币种
        if (item.balance == Double.MIN_VALUE) {
            holder.setText(R.id.tv_balance, "0.00")
        } else {
            holder.setText(R.id.tv_balance, item.balance.toString())
        }
        holder.setText(R.id.tv_balance_unit, item.currency)
    }

    fun setSelectIndex(index: Int) {
        notifyItemChanged(mSelectIndex)
        mSelectIndex = index
        notifyItemChanged(mSelectIndex)
    }

    fun getSelectIndex(): Int {
        return mSelectIndex
    }
}